home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / gethttp / gethttp.rexx < prev    next >
OS/2 REXX Batch file  |  1995-08-08  |  4KB  |  151 lines

  1. /*
  2.   $VER: GetHTTP 1.5 by Remco van Hooff
  3.   Rips http addresses from a file and saves
  4.   (adds) them to the AMosaic hotlist.
  5.  
  6.   Comments, improvements, suggestions are welcome.
  7.   You can reach me at: NLA   14:101/200.39
  8.                        AMY   39:153/201.39
  9.                        FIDO   2:286/407.39
  10.                        Inet  excalibr@igr.nl
  11.   Or at Excalibur BBS (+31-10-4187196), just leave
  12.   a msg to me (via the leave comment to sysop menu)
  13. */
  14.  
  15. /* No need for quotes when using volumes or filenames with spaces. */
  16. /* If used in/from DOpus use the 'No filename quote' option.       */
  17.  
  18. /*                        change these if needed                           */
  19. httpfile  = 'envarc:mosaic/.mosaic-hotlist-default'         /* the hotlist */
  20. copytoenv = 1 /* copy the hotlist to env: for for direct use (0=no, 1=yes) */
  21.  
  22.  
  23. ARG file
  24.  
  25. if (file = '') | (file = '?') then do
  26.   say; say 'No input file specified.'
  27.   say 'Usage: rx GetHTTP.rexx <file>'; say
  28.   exit
  29. end
  30.  
  31. if ~show('l','rexxreqtools.library') then 
  32.   if ~addlib('rexxreqtools.library',0,-30,0) then do
  33.     say "Couldn't find rexxreqtools.library"
  34.     exit
  35.   end
  36.  
  37. options results
  38.  
  39. dat = date()
  40. parse var dat dagnr maand jaar
  41. dag = left(date('W', date(S), 'S'), 3)
  42. datum = dag maand dagnr time()jaar
  43.  
  44. saved = 0
  45.   open(temp,file,'r')
  46.   msg = readch(temp,2097152) /* max size = 2MB, change if more is required */
  47.   msg = translate(msg, 'hpt', 'HPT')                /* Make 'http' lowercase.*/
  48.   check = pos('ttp://', msg)
  49.     if check = 0 then do
  50.       rtezrequest('No URL found.', '_Ok', 'GetHTTP')
  51.       exit
  52.     end
  53.   close(temp)
  54.   if check ~=0 then do
  55.     open(temp, file, 'r')
  56.       do while ~eof(temp)
  57.         msg = readln(temp)
  58.         msg = translate(msg, 'hpt', 'HPT')
  59.         parse var msg . 'ttp://' httpadres .
  60.         if httpadres ~= '' then do
  61.           lengte = length(httpadres)   
  62.           call filter(httpadres, lengte)
  63.           vraag = center(' Save this URL? ',lengte2,'-')
  64.           httpadres = rtgetstring(httpadres,vraag,'Get HTTP','_Save|_Abort|S_kip')
  65.           if rtresult = 1 then do
  66.             if ~exists(httpfile) then do
  67.               rtezrequest('Hotlist not found!', '_Ok', 'GetHTTP')
  68.               exit  
  69.             end 
  70.             else do
  71.               call open(http,httpfile,'a')
  72.               call writeln(http,httpadres||' '||datum)
  73.               call addname()
  74.               call close(http)
  75.               saved = 1
  76.             end
  77.           end
  78.           if rtresult = 2 then do
  79.             call copyenvarc()
  80.             exit
  81.           end
  82.         end
  83.       end
  84.     close(temp)
  85.   end
  86.   rtezrequest('No more URLs found.', '_Ok', 'GetHTTP')
  87.   call copyenvarc()
  88.  
  89. exit
  90.  
  91.  
  92. addname:
  93.   do forever
  94.     httpname = rtgetstring(,'Enter URL name','Get HTTP','_Ok|_Cancel')
  95.     if (rtresult = 1) & (httpname ~= '') then leave
  96.   end
  97.   call writeln(http,httpname)  
  98. return
  99.  
  100. filter:
  101.   adres = arg(1)
  102.   lngth = arg(2)
  103.   lf    = '0a'x
  104.   cr    = '0d'x  
  105.  
  106.   lnfd = pos(lf, adres)
  107.   if lnfd ~=0 then do
  108.     adres = delstr(adres, lnfd)
  109.   end
  110.  
  111.   cret = pos(cr, adres)
  112.   if cret ~=0 then do
  113.     adres = delstr(adres, cret)
  114.   end
  115. /*1.3*/
  116.   punt = lastpos('.', adres)
  117.   if punt ~=0 then lngth = length(adres)
  118.   if (punt = lngth) then do
  119.     adres = delstr(adres, punt)
  120.   end
  121.  
  122.   haak = lastpos(')', adres)
  123.   if haak ~=0 then do
  124.     adres =  delstr(adres, haak)
  125.   end
  126.  
  127.   komma = pos(',', adres)
  128.   if komma ~= 0 then do
  129.     adres = delstr(adres, komma)
  130.   end
  131.  
  132.   quote = pos("'", adres)
  133.   if quote ~= 0 then do
  134.     adres = delstr(adres, quote)
  135.   end
  136.  
  137.   dquote = pos('"', adres)
  138.   if dquote ~= 0 then do
  139.     adres = delstr(adres, dquote)
  140.   end
  141.  
  142.   httpadres = 'http://'||adres
  143.   lengte2 = length(httpadres)
  144. return
  145.  
  146. copyenvarc:
  147.   if (copytoenv = 1) & (saved = 1) then do
  148.     address command 'copy' httpfile 'env:mosaic'
  149.   end
  150. return
  151.